package com.altran.web.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name="consultores")
@NamedQueries({
	@NamedQuery(name = "buscarConsultorByNombre", 
		 	   query = "SELECT c " +
		 			   "from Consultor as c "+
		 			   "where nombre = :nombre "),
	
	@NamedQuery(name = "buscarConsultorById", 
	   query = "SELECT c " +
			   "from Consultor as c "+
			   "where id_consultor = :id_consultor "),
			   
	@NamedQuery(name= "obtenerConsultores", 
	   query = "SELECT c " +
			   "from Consultor as c ")
})

public class Consultor implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE)
	private int id_consultor;
	
	@Column(unique=true)
	private String nombre;
	private String telf;
	private String email;
	
	public Consultor() {}

	// TODO necesita hibernate constructor Consultor(id, ...) ??
	public Consultor(String nombre, String telf, String email) {
		super();
		this.nombre = nombre;
		this.telf = telf;
		this.email = email;
	}
	
	public int getId_consultor() {
		return id_consultor;
	}
	
	public void setId_consultor(int id_consultor) {
		this.id_consultor = id_consultor;
	}
	
	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public String getTelf() {
		return telf;
	}

	public void setTelf(String telf) {
		this.telf = telf;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((nombre == null) ? 0 : nombre.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Consultor other = (Consultor) obj;
		if (nombre == null) {
			if (other.nombre != null)
				return false;
		} else if (!nombre.equals(other.nombre))
			return false;
		return true;
	}
}
